package com.xueyi.system.auxiliaryReceive.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xueyi.common.core.utils.DateUtils;
import com.xueyi.common.core.web.result.AjaxResult;
import com.xueyi.system.auxiliaryReceive.domain.po.AuxiliaryReceivePo;
import com.xueyi.system.auxiliaryReceive.domain.query.AuxiliaryReceiveQuery;
import com.xueyi.system.auxiliaryReceive.domain.dto.AuxiliaryReceiveDto;
import com.xueyi.system.auxiliaryReceive.mapper.AuxiliaryReceiveMapper;
import com.xueyi.system.auxiliaryReceive.service.IAuxiliaryReceiveService;
import com.xueyi.system.auxiliaryReceive.manager.IAuxiliaryReceiveManager;
import com.xueyi.common.web.entity.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 投入品领用管理 服务层处理
 *
 * @author zlf
 */
@Service
public class AuxiliaryReceiveServiceImpl extends BaseServiceImpl<AuxiliaryReceiveQuery, AuxiliaryReceiveDto, IAuxiliaryReceiveManager> implements IAuxiliaryReceiveService {


    @Autowired
    private AuxiliaryReceiveMapper auxiliaryReceiveMapper;

    /**
     * 查询投入品领用对象列表 | 数据权限 | 附加数据
     *
     * @param auxiliaryReceive 投入品领用对象
     * @return 投入品领用对象集合
     */
    @Override
    //@DataScope(userAlias = "createBy", mapperScope = {"AuxiliaryReceiveMapper"})
    public List<AuxiliaryReceiveDto> selectListScope(AuxiliaryReceiveQuery auxiliaryReceive) {
        return baseManager.selectListExtra(auxiliaryReceive);
    }

    /**
     * 投入品使用情况
     * @return
     */
    @Override
    public AjaxResult getIAuxiliaryReceiveList() {

        QueryWrapper<AuxiliaryReceivePo> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("sum(auxiliary_num) as auxiliaryNum,name");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
        queryWrapper.like("create_time",dateFormat.format(new Date()));
        queryWrapper.groupBy("name");
        List<Map<String, Object>> list = auxiliaryReceiveMapper.selectMaps(queryWrapper);
        return AjaxResult.success(list);
    }
}
